﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace VirtualOperator
{
    /*
     * Configuration needed to connect to PicsNC
     */ 
    public class VOConfig
    {
        private string name;
        public string Name { get { return name; } set { name = value; } }
        private string password;
        public string Password { get { return password; } set { password = value; } }
        private int id;
        public int Id { get { return id; } set { id = value; } }
        private int port;
        public int Port { get { return port; } set { port = value; } }
        private string ipAddress;
        public string IPAddress { get { return ipAddress; } set { ipAddress = value; } }


        public void save(string filename)
        {
            // create a writer and open the file
            TextWriter tw = new StreamWriter(filename);

            // write a line of text to the file
            tw.Write(TransportLayer.NodeToolsLibrary.Serial.SerializeObject(this));

            // close the stream
            tw.Close();
        }
        //wczytanie konfiguracji
        public static VOConfig fopen(string filename)
        {
            TextReader tr = new StreamReader(filename);
            String str = "";
            String input = null;

            while ((input = tr.ReadLine()) != null)
            {
                str += input;
            }
            tr.Close();
            return ((VOConfig)TransportLayer.NodeToolsLibrary.Serial.DeserializeObject(str, typeof(VOConfig)));
        }
    
        public override string ToString()
        {
            return name + "_" + id + " " +ipAddress+ ":" +port;
        }

    }
}
